package interaction.sampling.matching;

import interaction.sampling.Sample;
import interaction.sampling.SampleSet;
import interaction.sampling.Transform;
/**
 * Gives a measure on how the amount of intensity changes in the fft spectrum
 * resemble each other between a test sample and a comparison sample set.
 */
public class DeltaRangeLengthMatcher implements Matcher {
	public double match(Sample test, SampleSet comparison)
	{
		Transform t = getDeviationTransform();
		test = t.apply(test);
		comparison = comparison.apply(t);
		
		int testSize = test.size();
		double comparisonSize = comparison.getSizes().getAverage();
		
		return -Math.abs(testSize - comparisonSize)/comparisonSize;
	}
	
	public double getAcceptanceTreshold()
	{
		return -0.3;
	}
	
	private Transform getDeviationTransform()
	{
		return new Transform() {
			public Sample apply(Sample input) {
				return input.getDeltas().compressRange(0.1);
			}
		};
	}
	
}
